package cn.sc.summer.gateway.config;

import cn.sc.summer.gateway.handler.CreateImageCodeHandler;
import cn.sc.summer.gateway.handler.CreateSmsCodeHandler;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

/**
 * 类名：路由转发，基础接口路由配置信息
 *
 * @author a-xin
 * @date 2023/8/18 10:47
 */
@Slf4j
@Configuration
@AllArgsConstructor
public class RouterFunctionConfig {

    private final CreateImageCodeHandler createImageCodeHandler;

    private final CreateSmsCodeHandler createSmsCodeHandler;

    @Bean
    public RouterFunction<ServerResponse> routerFunction() {
        log.info("==> Start Initializing the gateway routing config...");
        return RouterFunctions.route(
                        RequestPredicates.GET("/imageCode")
                                .and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), createImageCodeHandler)
                .andRoute(RequestPredicates.GET("/smsCode")
                        .and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), createSmsCodeHandler);
    }

}

